package test.rollergdx.core;

import org.jbox2d.collision.shapes.CircleShape;
import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.Body;
import org.jbox2d.dynamics.BodyDef;
import org.jbox2d.dynamics.BodyType;
import org.jbox2d.dynamics.World;
import org.jbox2d.dynamics.joints.WheelJointDef;

import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;



public class RollerGDX implements ApplicationListener {

	Texture texture;
	SpriteBatch batch;
	float elapsed;

	@Override
	public void create () {
		texture = new Texture(Gdx.files.internal("libgdx-logo.png"));
		batch = new SpriteBatch();

		World world = new World(new Vec2(0,-10));
		
		CircleShape circleShape = new CircleShape();
		circleShape.setRadius(1);
		
		BodyDef bd = new BodyDef();
		bd.type = BodyType.DYNAMIC;
		
		Body body1 = world.createBody(bd);
		body1.createFixture(circleShape, 0);

		Body body2 = world.createBody(bd);
		body2.createFixture(circleShape, 0);
		
		
		WheelJointDef jd = new WheelJointDef();
		Vec2 axis = new Vec2(0.0f, 1.0f);

		jd.initialize(body1, body2, body2.getPosition(), axis);
		jd.motorSpeed = 0.0f;
		jd.enableMotor = false;
		//world.createJoint(jd);
	}

	@Override
	public void resize (int width, int height) {
	}

	@Override
	public void render () {
		elapsed += Gdx.graphics.getDeltaTime();
		Gdx.gl.glClearColor(0, 0, 0, 0);
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		batch.begin();
		batch.draw(texture, 100+100*(float)Math.cos(elapsed), 100+25*(float)Math.sin(elapsed));
		batch.end();
	}

	@Override
	public void pause () {
	}

	@Override
	public void resume () {
	}

	@Override
	public void dispose () {
	}
	

	
}
